package com.umfwechat.h5.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.umfwechat.core.loggers.LoggersFactory;

import net.sf.json.JSONObject;

/**
 * Created by hopeone on 2017/5/11.
 */


@Controller
@RequestMapping(value = "/testspringmvc")
public class TestController {

//    @Resource
//    UserServiceRemote userServiceRemote;

    @RequestMapping(value = "/test")
    public ModelAndView test(HttpServletRequest request, HttpServletResponse response) throws Exception
    {
    	LoggersFactory.DETAIL_LOGGER().info("spring 框架测试开始");

        try {
        	System.out.println("spring json响应框架测试结束");
        	System.out.println(1/0);
//            userServiceRemote.bindEmail(new ReqMessage());
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
        LoggersFactory.DETAIL_LOGGER().info("spring 框架测试完成");
        return new ModelAndView();


    }


    @RequestMapping(value = "/jsontest",produces="application/json;charset=UTF-8")
    @ResponseBody
    public String jsontest() throws Exception{
    	System.out.println("spring json响应框架测试开始");
    	LoggersFactory.DETAIL_LOGGER().info("spring json响应框架测试开始");
        Map<String, Object> resultMap = new HashMap<String, Object>();
        resultMap.put("rank", "李洪鹏"); //身份
        try {
        	System.out.println("spring json响应框架测试结束");
        	System.out.println(1/0);
//            userServiceRemote.bindEmail(new ReqMessage());
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
//            throw new BusinessException();
        }
        LoggersFactory.DETAIL_LOGGER().info("spring json响应框架测试结束");
        
        return JSONObject.fromObject(resultMap).toString();
    }
}
